package com.atguigu.test;

import org.apache.http.HttpHost;
import org.elasticsearch.action.get.GetRequest;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;

import java.io.IOException;

public class test_es_06_doc_select {

    public static void main(String[] args) throws IOException {

        //创建es客户端
        RestHighLevelClient esClient = new RestHighLevelClient(RestClient.builder(new HttpHost("127.0.0.1",9200,"http")));

        //创建查询对象
        GetRequest request = new GetRequest();
        request.index("user").id("1001");

        //查询文档、发送请求
        GetResponse response = esClient.get(request, RequestOptions.DEFAULT);

        System.out.println("_index: "+response.getIndex());
        System.out.println("_type: "+response.getType());
        System.out.println("_id: "+response.getId());
        System.out.println("source: "+response.getSourceAsString());
        //关闭es客户端
        esClient.close();
    }
}
